package com.base.cn.platform.os.controller.op.feedback;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.service.manage.op.feedback.OpFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 用户反馈管理
 * @author zsw
 * @since 2018/4/25
 */
@Controller
@RequestMapping("/admin/op/feedback")
public class AdminOpFeedbackController extends AdminBaseController {

    @Autowired
    private OpFeedbackService opFeedbackService;

    /**
     * 查询反馈列表
     * @param model
     * @return 反馈列表
     */
    @RequestMapping("/queryFeedbackList")
    public String queryFeedbackList(Model model){
        return resultPage("/op/feedback/feedback-list");
    }

    /**
     * ajax加载用户反馈列表
     * @param model
     * @param currentPage 当前页码
     * @param params 查询条件
     * @return 反馈列表页面
     */
    @RequestMapping("/ajaxQueryFeedbackList")
    public String ajaxQueryFeedbackList(Model model,
                                        @RequestParam(value = "currentPage", required = false,defaultValue = "1")int currentPage,
                                        @RequestBody Map<String, Object> params){
        Map<String, Object> dataMap = opFeedbackService.queryFeedbackList(currentPage, params);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/op/feedback/feedback-ajax-list");
    }

    /**
     * 查询用户反馈详情
     * @param model
     * @param feedbackId 反馈id
     * @return 反馈详情页面
     */
    @RequestMapping("/showFeedbackInfo")
    public String showFeedbackInfo(Model model,
                               @RequestParam(value = "feedbackId",required = false,defaultValue = "0") BigDecimal feedbackId){
        Map<String, Object> feedback = opFeedbackService.showFeedbackInfo(feedbackId);
        model.addAttribute("dataMap", feedback);
        return resultPage("/op/feedback/feedback-info");
    }

    /**
     * 跳转修改用户反馈详情页面
     * @param model
     * @param feedbackId 反馈id
     * @return 反馈详情页面
     */
    @RequestMapping("/toSaveUpdateFeedback")
    public String toSaveUpdateFeedback(Model model,
                                   @RequestParam(value = "feedbackId",required = false,defaultValue = "0") BigDecimal feedbackId){
        Map<String, Object> feedback = opFeedbackService.showFeedbackInfo(feedbackId);
        model.addAttribute("dataMap", feedback);
        return resultPage("/op/feedback/update-feedback");
    }

    /**
     * 修改用户反馈
     * @param model
     * @param feedback saveUpdateFeedback
     * @return 修改反馈页面
     */
    @RequestMapping("/saveUpdateFeedback")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "保存或更新用户反馈")
    public Map<String,Object> saveUpdateFeedback(Model model,
                                     @RequestBody Map<String,Object> feedback){
        return opFeedbackService.saveUpdateFeedback(feedback);
    }

    /**
     * 删除用户反馈
     * @param feedbackIds 反馈id串
     * @return
     */
    @RequestMapping("/deleteFeedback")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "删除用户反馈")
    public Map<String,Object> deleteFeedback(@RequestParam("feedbackIds")String feedbackIds){
        return opFeedbackService.deleteFeedback(feedbackIds);
    }
}
